/**
 * @file LogEvent.cpp
 * @author  haifeng (haifengxiao@icloud.com)
 * @brief
 * @version 0.1
 * @date 2021-07-06
 *
 * @copyright Copyright (c) 2021
 *
 */

#include <map>
#include <stdarg.h>

#include "LogEvent.h"

namespace Chen {
    namespace Log {

        LogEvent::LogEvent(std::shared_ptr<Logger> logger, LogLevel::Level level
            , const char* file, int32_t line, uint32_t elapsa
            , uint32_t thread_id, uint32_t fiber_id, uint64_t time
            , const std::string& thread_name)
            :m_logger(logger)
            , m_level(level)
            , m_file(file)
            , m_line(line)
            , m_elapse(elapsa)
            , m_threadId(thread_id)
            , m_fiberId(fiber_id)
            , m_time(time)
            , m_threadName(thread_name) {

        }

        void LogEvent::format(const char* fmt, ...) {
            va_list al;
            va_start(al, fmt);
            format(fmt, al);
            va_end(al);

        }

        void LogEvent::format(const char* fmt, va_list al) {
            char* buf = nullptr;
            int len = vasprintf(&buf, fmt, al);
            if (len != -1) {
                m_ss << std::string(buf, len);
                free(buf);
            }
        }

    }//namespace Log
}//namespace Chen